package com.bishe.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bishe.entity.Warehouse;
import com.bishe.entity.response.R;
import com.bishe.service.WarehouseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (Warehouse)表控制层
 *
 * @author makejava
 * @since 2024-03-04 00:02:38
 */
@CrossOrigin
@RestController
@RequestMapping("warehouse")
public class WarehouseController {
    /**
     * 服务对象
     */
    @Resource
    private WarehouseService warehouseService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param warehouse 查询实体
     * @return 所有数据
     */
    @GetMapping("/toPage")
    @ApiOperation("分页查询所有数据")
    public R selectAll(Page<Warehouse> page, Warehouse warehouse) {
        return R.ok(this.warehouseService.page(page, new QueryWrapper<>(warehouse)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @ApiOperation("通过主键查询单条数据")
    public R selectOne(@PathVariable Serializable id) {
        return R.ok(this.warehouseService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param warehouse 实体对象
     * @return 新增结果
     */
    @PostMapping
    @ApiOperation("新增数据")
    public R insert(@RequestBody Warehouse warehouse) {
        return R.ok(this.warehouseService.save(warehouse));
    }

    /**
     * 修改数据
     *
     * @param warehouse 实体对象
     * @return 修改结果
     */
    @PutMapping
    @ApiOperation("修改数据")
    public R update(@RequestBody Warehouse warehouse) {
        return R.ok(this.warehouseService.updateById(warehouse));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    @ApiOperation("删除数据")
    public R delete(@RequestParam("idList") List<Long> idList) {
        return R.ok(this.warehouseService.removeByIds(idList));
    }
}

